package org.example.day02;

/**
 * 第一章节1.11:守护线程
 *      当进程不存在非守护线程时，守护线程自动消亡
 */
public class MyThread12 extends Thread{
    private int i = 0;

    @Override
    public void run() {
        try {
            while(true){
                i++;
                System.out.println("i=" + (i));
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
            MyThread12 m12 = new MyThread12();
            //设置为守护线程
            m12.setDaemon(true);
            m12.start();
            Thread.sleep(5000);
            System.out.println("主线程即将执行完毕（非守护线程）");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

//i=1
//i=2
//i=3
//i=4
//i=5
//主线程即将执行完毕（非守护线程）